import * as math from 'mathjs'
export default {
  /**
   * format 得到string
   * number 得到number
   *
   */
  // 加
  add(...numbers) {
    const count = numbers.reduce((sum, number) =>
      math.add(math.bignumber(sum), math.bignumber(number || 0))
    )
    return math.number(count)
  },
  // 乘
  multiply(...numbers) {
    const count = numbers.reduce((sum, number) =>
      math.multiply(math.bignumber(sum), math.bignumber(number || 0))
    )
    return math.number(count)
  },
  // 减
  subtract(...numbers) {
    const count = numbers.reduce((sum, number) =>
      math.subtract(math.bignumber(sum), math.bignumber(number || 0))
    )
    return math.number(count)
  },
  // 除
  divide(...numbers) {
    const count = numbers.reduce((sum, number) =>
      math.divide(math.bignumber(sum), math.bignumber(number || 0))
    )
    return math.number(math.round(count, 2))
  },
  // 四舍五入保留两位小数
  keepTwoDecimal(num) {
    return math.round(num, 2)
  },
}
